/**
 *
 */
package l1j.opqlo.NewSystem;

import l1j.server.server.model.Instance.L1NpcInstance;
import l1j.server.server.serverpackets.ServerBasePacket;
import l1j.server.server.utils.Random;

/**
 * @author opqlo
 *
 */
public class A_ColorMessage extends ServerBasePacket {
	private final static int[] color = { 1, // 蜜語 色
			3, // 廣播
			4, // 血盟顏色
			11, // 隊伍 橘色
			12, // 買賣頻道
			15, // 紫色
			17 // 暗綠色
	};
	
	
	public static final int 密語色 = 1
			, 廣播色 =3
			, 血盟顏色 = 4
			, 隊伍橘色 = 11
			, 買賣頻道 = 12
			, 紫色 = 15
			, 暗綠色 = 17;
	
	

	public A_ColorMessage(final int code, final String text) {
		if (code == 2 || code == 15) {
			this.writeC(S_OPCODE_NORMALCHAT);
			this.writeC(code);
			this.writeD(0);
		} else {
			this.writeC(S_OPCODE_GLOBALCHAT);
			this.writeC(code);
		}

		this.writeS(text);
	}

	public A_ColorMessage(final L1NpcInstance npc, final int code,
			final String text) {
		this.writeC(S_OPCODE_NORMALCHAT);
		this.writeC(code);
		this.writeD(npc.getId());
		this.writeS(npc.getName() + ": " + text);
	}

	public A_ColorMessage(final String text) {
		final int length = Random.nextInt(color.length);

		if (color[length] == 2 || color[length] == 15) {
			this.writeC(S_OPCODE_NORMALCHAT);
			this.writeC(color[length]);
			this.writeD(0);
		} else {
			this.writeC(S_OPCODE_GLOBALCHAT);
			this.writeC(color[length]);
		}

		this.writeS(text);
	}

	// //@Override
	@Override
	public byte[] getContent() {
		return this.getBytes();
	}
}
